//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using CommunityServer.Components;

namespace CommunityServer.Files.Components
{
	/// <summary>
	/// Summary description for GalleryComment.
	/// </summary>
	public class EntryComment : Post
	{
		public EntryComment()
		{
		}

        #region Post Implementation
        private Folder _gallery = null;
        public override Section Section
        {
            get
            {
                if(_gallery == null)
                    _gallery = Folders.GetFolder(Entries.GetEntry(this.ParentID).SectionID);

                return _gallery;
            }
            set
            {
                _gallery = value as Folder;
            }
        }
        #endregion

		public FileGalleryPostType FileGalleryPostType
		{
			get { return FileGalleryPostType.Comment; }
		}

		public string ViewPostURL
		{
			get
			{
				return FileGalleryUrls.Instance().ViewEntry(this.Section.ApplicationKey, this.ParentID);
			}
		}

		public string ViewAuthorURL
		{
			get
			{
				if(this.HasTitleUrl)
					return this.TitleUrl;
				else
					return SiteUrls.Instance().UserProfile(this.Username); 
			}
		}

		/// <summary>
		/// Url submitted in a comment
		/// </summary>
		public string TitleUrl
		{
			get { return this.GetExtendedAttribute("Website"); }
			set { this.SetExtendedAttribute("Website", value); }
		}

		/// <summary>
		/// Does this post have a title url
		/// </summary>
		public bool HasTitleUrl
		{
			get { return (TitleUrl != null && TitleUrl.Length > 0); }
		}

		/// <summary>
		/// Name submitted when the post was saved
		/// </summary>
		public string SubmittedUserName
		{
			get { return GetString("Name", null); }
			set { this.SetExtendedAttribute("Name", value); }
		}

		/// <summary>
		/// When the post was saved, did the user submit a different name
		/// </summary>
		public bool HasSubmittedUserName
		{
			get { return !Globals.IsNullorEmpty(this.SubmittedUserName); }
		}

		public string DisplayName
		{
			get 
			{
				if (this.User != null && !this.User.IsAnonymous)
					return this.User.DisplayName;
				else
					return HasSubmittedUserName ? this.SubmittedUserName : this.Username; 
			}
		}

	}
}
